Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Using the UNDO statement
Progress undoes a transaction automatically if it detects an error at the database level, for example, because of a unique key violation. In many cases, your application logic also wants to undo a transaction when you detect a violation of your business logic. The
UNDOstatement lets you control when to cancel the effects of a transaction on your own. It also lets you define just how much of your procedure logic to undo.Here is the syntax of the
UNDOstatement:
In its simplest form, you can use the
UNDOkeyword as its own statement. In this case, Progress undoes the innermost containing block with the error property, which can be:You can change this default by specifying a block label to undo. You can place a block name anywhere in your procedure. The block name must adhere to the same rules as a variable name and it must be followed by a colon. If you use this block name in an
UNDOstatement, it identifies how far back you want Progress to undo transactional work.The default action on an
UNDOis to attempt to retry the current block. In Progress, a block of code that prompts the user for field values can be retried; that is, having entered invalid data, the user can re-enter different values. If you are writing well-structured procedures that do not mix user interface elements with database logic, then retrying a block never results in a user entering different values. Progress recognizes this and changes the action to aNEXTof an iterating block, or aLEAVEof a noniterating block, so this is effectively the default for transactions not involving user interface events.You can change this default action as well. If you specify
LEAVE, you can name the block to leave. This defaults to the block you undo.If you specify
NEXTwithin an iterating block, then after theUNDOProgress proceeds to the next iteration of either the block whose label you specify or the block you undo as a default. Use theNEXToption if each iteration of a repeating block is its own transaction (the default) and if you want Progress to keep trying to apply changes to other records, for example, as Progress walks through a set of records in aFOR EACHblock.If you specify
RETRY, then you can retry either the current block (the default) or the same block you applied theUNDOstatement to. Again, in a properly structured application, you do not need to use theRETRYoption.Finally, you can
RETURNout of the current procedure. You canRETURNERROR, which raises the Progress error condition, or you can useRETURN NO-APPLYto cancel the effect of the last user-interface event. Once again, this is not an option you would normally use in server-side business logic. TheRETURNoption can also specify areturn-string, which becomes theRETURN-VALUEin the procedure you return to.You can also specify
UNDOas an option on aDO,FOR, orREPEATblock, as you did in yoursaveOrderexample procedure:
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |